<?php


namespace App\Services;

use App\Models\NoticeModel;

/**
 * 通知公告-服务类
 * @author 牧羊人
 * @since 2020/8/30
 * Class NoticeService
 * @package App\Services
 */
class NoticeService extends BaseService
{
    /**
     * 构造函数
     * @author 牧羊人
     * @since 2020/8/30
     * NoticeService constructor.
     */
    public function __construct()
    {
        $this->model = new NoticeModel();
    }

    /**
     * 获取数据列表
     * @return array
     * @since 2020/8/30
     * @author 牧羊人
     */
    public function getList()
    {
        $param = request()->all();
        // 查询条件
        $map = [];
        // 通知来源
        $source = isset($param['source']) ? trim($param['source']) : 0;
        if ($source) {
            $map[] = ['source', '=', "$source"];
        }
        return parent::getList($map); // TODO: Change the autogenerated stub
    }

    /**
     * 添加或编辑
     * @return array
     * @since 2020/8/30
     * @author 牧羊人
     */
    public function edit()
    {
        // 参数
        $data = request()->all();
        // 发布状态
        $status = intval($data['status']);
        if ($status == 3) {
            $data['publish_time'] = strtotime($data['publish_time']);
        } else {
            $data['publish_time'] = 0;
        }
        return parent::edit($data); // TODO: Change the autogenerated stub
    }

}
